package com.ryhx.ssm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ryhx.ssm.dao.UserTMapper;
import com.ryhx.ssm.domain.UserT;
import com.ryhx.ssm.domain.UserTExample;
import com.ryhx.ssm.domain.UserTExample.Criteria;
import com.ryhx.ssm.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService{
	@Resource
	private UserTMapper usermapper;

	public UserT getUserById(int userId) {
		return usermapper.selectByPrimaryKey(userId);
	}
	public List<UserT> getUserList() {
		UserTExample example=new UserTExample();
		return usermapper.selectByExample(example);
	}
	public void addUser(UserT user) {
		int i = usermapper.insert(user);
		if(i!=1){
			new RuntimeException("数据库服务器异常");
		}
	}
	public UserT getUserByUsername(String username) {
		UserTExample example=new UserTExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserNameEqualTo(username);
		List<UserT> list = usermapper.selectByExample(example);
		if(list!=null){
			return list.get(0);
		}
		return null;
	}
	@Override
	public UserT getUserByUsernameAndPassword(String username, String password) {
		UserTExample example=new UserTExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserNameEqualTo(username);
		criteria.andPasswordEqualTo(password);
		List<UserT> list = usermapper.selectByExample(example);
		if(list!=null){
			return list.get(0);
		}
		return null;
	}
}
